package com.hospital.pet.love.lovepethospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hospital.pet.love.lovepethospital.domain.Employee;
import com.hospital.pet.love.lovepethospital.dto.employee.EmployeeAddDto;
import com.hospital.pet.love.lovepethospital.dto.employee.EmployeeUpdateDto;
import com.hospital.pet.love.lovepethospital.dto.employee.JobDepartmentDto;
import com.hospital.pet.love.lovepethospital.resp.Result;
import com.hospital.pet.love.lovepethospital.resp.ResultCodeEnum;
import com.hospital.pet.love.lovepethospital.service.EmployeeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author RoselleShaw
 * @create 2024-04-19 20:21
 */
@RestController
@RequestMapping("/employee")
@Tag(name = "员工管理")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @GetMapping("/get")
    @Operation(summary = "员工获取自己信息")
    public Result<Employee> get() {
        Employee employee = employeeService.get();
        return Result.build(employee, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/update")
    @Operation(summary = "员工修改自己信息")
    public Result<Void> update(@RequestBody EmployeeUpdateDto employeeupdateDto) {
        employeeService.update(employeeupdateDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/get-by-page/{pageNum}/{pageSize}")
    @Operation(summary = "查询所有员工（超级管理员）")
    public Result<Page<Employee>> getByPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        Page<Employee> employeePage = employeeService.getByPage(pageNum, pageSize);
        return Result.build(employeePage, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "删除员工（超级管理员）")
    public Result<Void> delete(@PathVariable Integer id) {
        employeeService.delete(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/add")
    @Operation(summary = "添加员工（超级管理员）")
    public Result<Void> add(@RequestBody EmployeeAddDto employeeAddDto) {
        employeeService.add(employeeAddDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/job-department")
    @Operation(summary = "设置员工职位和科室（超级管理员）")
    public Result<Void> jobDepartment(@RequestBody JobDepartmentDto JobDepartmentDto) {
        employeeService.jobDepartment(JobDepartmentDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/get-free-doctor")
    @Operation(summary = "获取所有医生")
    public Result<List<Employee>> getAllDoctor() {
        List<Employee> doctors = employeeService.list(
                new LambdaQueryWrapper<Employee>()
                        .eq(Employee::getJob, "医生")
        );
        return Result.build(doctors, ResultCodeEnum.SUCCESS);
    }

}
